clear all

set seed 249233
local bsiter = 10
 

cd "/Users/sambuehl/Dropbox/Demand_for_Information/DATA_ANALYSIS/"

* make datasets lean



set more off

use "data/data_all.dta", replace



drop if session == 4 | session == 1 | session == 10

merge m:1 subj using "data/alphas.dta"
drop _merge

// keep if rogue == 0


gen logit_p11 = log(p11/(1-p11))
gen logit_p00 = log(p00/(1-p00))
gen loglik11 = log(a/(1-b))
gen loglik00 = log(b/(1-a))

save "data/pool.dta", replace

***** initial estimate


use "data/pool.dta", replace

keep if tag_sub == 1
keep sub id alpha se_alpha

gen id_new = _n

expandby 10, by(id_new)
sort id_new
gen info_structure = _n
replace info_structure = info_structure - 10*floor(info_structure/10)
replace info_structure = 10 if info_structure == 0

qui merge m:1 subject info_struc using "data/pool.dta"
drop if _merge == 2
drop _merge


gen pred_logit_p11 = alpha * loglik11
gen pred_logit_p00 = alpha * loglik00


* estimation 

gen pred_p11 = exp(pred_logit_p11)/(1 + exp(pred_logit_p11))
gen pred_p00 = exp(pred_logit_p00)/(1 + exp(pred_logit_p00))
replace pred_p00 = 1 if pred_p00 == .
gen pred_v_pred = b_p1 * pred_p11 + (1 - b_p1) * pred_p00


gen diff = v - v_pred_true_all
gen diff_sim = pred_v_pred - v_pred_true_all
gen diff_emp = v_pred - v_pred_true_all
gen diff_emp_upd = v_pred_true_uncond - v_pred_true_all

* generate the aggregate graph from part 1 using the simulated data


preserve
gen est = diff_sim
keep if rogue == 0
collapse est, by(info_str)
twoway (bar est info_s), ///
	   ytitle("Valuation Difference Predicted by Estimated Responsiveness") ///
       xtitle("Information Structure") ///
       xlabel(1 "S1" 2 "S2" 3 "A1" 4 "A2" 5 "S3" 6 "B1" 7 "A3" 8 "B2" 9 "S4" 10 "B3") ///
       ylabel(-.005(.02).005) ///
       title("") ///
       legend(off)
graph export "graphs/responsivenessAggregate_nonrogue.pdf",replace
restore


preserve
gen est = diff_sim
keep if alpha >= 0
collapse est, by(info_str)
twoway (bar est info_s), ///
	   ytitle("Valuation Difference Predicted by Estimated Responsiveness") ///
       xtitle("Information Structure") ///
       xlabel(1 "S1" 2 "S2" 3 "A1" 4 "A2" 5 "S3" 6 "B1" 7 "A3" 8 "B2" 9 "S4" 10 "B3") ///
       ylabel(-.04(.02).02) ///
       title("Responsiveness Prediction (Benchmark: Bayes Valuation)") ///
       ytitle("Deviation from benchmark (%-points)") ///
       legend(off)
graph export "graphs/responsivenessAggregate_all.pdf",replace
restore



preserve
gen est = diff
keep if rogue == 0
collapse est, by(info_str)
twoway (bar est info_s), ///
	   ytitle("True difference") ///
       xtitle("Information Structure") ///
       xlabel(1 "S1" 2 "S2" 3 "A1" 4 "A2" 5 "S3" 6 "B1" 7 "A3" 8 "B2" 9 "S4" 10 "B3") ///
       ylabel(-.06(.015).045) ///
       legend(off)
// graph export "graphs/responsivenessAggregate.pdf",replace
restore





preserve
gen est = diff
keep if alpha < 1 & rogue == 0
collapse est, by(info_str)
twoway (bar est info_s), ///
	   ytitle("Valuation Difference Predicted by Estimated Responsiveness") ///
       xtitle("Information Structure") ///
       xlabel(1 "S1" 2 "S2" 3 "A1" 4 "A2" 5 "S3" 6 "B1" 7 "A3" 8 "B2" 9 "S4" 10 "B3") ///
       ylabel(-.12(.03).09) ///
       legend(off)
// graph export "graphs/responsivenessAggregate.pdf",replace
restore



preserve
gen est = diff_sim
keep if alpha < 1 & rogue == 0
collapse est, by(info_str)
twoway (bar est info_s), ///
	   ytitle("Valuation Difference Predicted by Estimated Responsiveness") ///
       xtitle("Information Structure") ///
       xlabel(1 "S1" 2 "S2" 3 "A1" 4 "A2" 5 "S3" 6 "B1" 7 "A3" 8 "B2" 9 "S4" 10 "B3") ///
       ylabel(-.06(.03).045) ///
       legend(off)
// graph export "graphs/responsivenessAggregate.pdf",replace
restore



preserve
gen est = diff
keep if alpha > 1 & rogue == 0
collapse est, by(info_str)
twoway (bar est info_s), ///
	   ytitle("Valuation Difference Predicted by Estimated Responsiveness") ///
       xtitle("Information Structure") ///
       xlabel(1 "S1" 2 "S2" 3 "A1" 4 "A2" 5 "S3" 6 "B1" 7 "A3" 8 "B2" 9 "S4" 10 "B3") ///
       ylabel(-.12(.03).09) ///
       legend(off)
// graph export "graphs/responsivenessAggregate.pdf",replace
restore



preserve
gen est = diff_sim
keep if alpha > 1 & rogue == 0
collapse est, by(info_str)
twoway (bar est info_s), ///
	   ytitle("Valuation Difference Predicted by Estimated Responsiveness") ///
       xtitle("Information Structure") ///
       xlabel(1 "S1" 2 "S2" 3 "A1" 4 "A2" 5 "S3" 6 "B1" 7 "A3" 8 "B2" 9 "S4" 10 "B3") ///
       ylabel(-.12(.03).09) ///
       legend(off)
// graph export "graphs/responsivenessAggregate.pdf",replace
restore




rename v_pred_true_all v_b
gen v_sim = v_b + diff_sim

reg v_sim v_b asymmetry boundary, vce(cluster subj)
outreg2 v_b asymmetry boundary using "tables/responsivenessAcross", tex replace
test _b[v_b] == 1
reg v v_b asymmetry boundary, vce(cluster subj)
test _b[v_b] == 1
outreg2 v_b asymmetry boundary using "tables/responsivenessAcross", tex
reg v_sim v_b asymmetry boundary if alpha < 1, vce(cluster subj)
test _b[v_b] == 1
outreg2 v_b asymmetry boundary using "tables/responsivenessAcross", tex 
reg v v_b asymmetry boundary if alpha < 1, vce(cluster subj)
test _b[v_b] == 1
outreg2 v_b asymmetry boundary using "tables/responsivenessAcross", tex 
reg v_sim v_b asymmetry boundary if alpha > 1, vce(cluster subj)
test _b[v_b] == 1
outreg2 v_b asymmetry boundary using "tables/responsivenessAcross", tex 
reg v v_b asymmetry boundary if alpha > 1, vce(cluster subj)
test _b[v_b] == 1
outreg2 v_b asymmetry boundary using "tables/responsivenessAcross", tex 


gen alphaBin = alpha < 1
gen aB_vb = alphaBin * v_b
gen aA = alphaBin * asymmetry
gen aBoundary = alphaBin * boundary

reg v v_b asymmetry boundary aB_vb aA aBoundary, vce(cluster subj)
reg v v_b asymmetry boundary aB_vb aA aBoundary if rogue == 0, vce(cluster subj)





gen alpha_vb = alpha * v_b
gen alpha_asy = alpha * asymmetry
gen alpha_boundary = alpha * boundary

reg v v_b asymmetry boundary alpha_vb alpha_asy alpha_boundary, vce(cluster subj)
reg v v_b asymmetry boundary alpha_vb alpha_asy alpha_boundary if rogue == 0, vce(cluster subj)



* Does controling for truncation cause a flip? 

preserve
local ll = 0.55
local ul = 0.95
keep if v_b >= `ll' & v_b <= `ul'
tobit v v_b asymmetry boundary, ll(`ll') ul(`ul')
tobit v v_b asymmetry boundary if alpha > 1, ll(`ll') ul(`ul')
tobit v v_b asymmetry boundary if alpha < 1, ll(`ll') ul(`ul')
restore



postfile respAcross vb asy bound const type using "data/gradInfoControlsBootstrap", replace
local bsiter = 1000
set seed 149797

forvalues d = 1/`bsiter' {
reg v v_b asymmetry boundary, vce(cluster subj)
post respAcross (_b[v_b]) (_b[asymmetry]) (_b[boundary]) 

reg v v_b asymmetry boundary if alpha < 1, vce(cluster subj)
reg v v_b asymmetry boundary if alpha > 1, vce(cluster subj)


}

postclose respAcross

